package cn.tedu.base.response;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Setter
@Getter
@AllArgsConstructor
@NoArgsConstructor
public class JsonResult {

    private Integer code;

    private String message;

    private Object data;



    public JsonResult(StatusCode statusCode){
        this.code = statusCode.getCode();
        this.message =statusCode.getMsg();
    }

    public JsonResult(StatusCode statusCode,Object data){
        this.code = statusCode.getCode();
        this.message = statusCode.getMsg();
        this.data = data;
    }

    //针对登录成功成功且有返回值的
    public static JsonResult loginOk(Object data){
        return new JsonResult(StatusCode.LOGIN_SUCCESS,data);
    }

    //针对未登录失败的
    public static JsonResult notLogin(){
        return new JsonResult(StatusCode.NOT_LOGIN);
    }



    //已经写好的公用类不要随便删，否则可能造成不可预知的错误
    public static JsonResult ok(Object data){
        return loginOk(data);
    }
    //已经写好的公用类不要随便删，否则可能造成不可预知的错误
    public static JsonResult ok(){
        return loginOk(null);
    }
}
